<script>
	import api from '@/common/request/index'
	import helpers from '@/common/utils/helpers.js'
	//#ifdef H5
	// 引用调试控制台
	// import vconsole from 'common/utils/vconsole.min.js'
	import wxScan from '@/common/utils/wx-scan.js';
	// #endif
	export default {
		globalData: {
			currMerchantStore: {
				id: '',
				storeName: ''
			},
			//底部导航栏
			tab: {
				show: false,
				name: 'my'
			},
			//是否提示获取用户信息
			userInformation: true,
			// 小程序当前版本
			version: '',
			// 当前webSocket连接的ID
			socketId: '',
			//蓝牙格子机是否支付中,用来防止拉起支付触发断开蓝牙方法
			isPaymentInProgress: false,
		},

		onLaunch: function(options) {
			// #ifdef MP-ALIPAY  || MP-WEIXIN
			this.upgradeVersion();
			console.log('App Launch');
			this.getAppletVersion();
			// #endif

			//#ifdef H5
			// 引用调试控制台
			// var vConsole = new vconsole();
			// #endif

		},
		onShow: function() {
			console.log('App Show');
		},
		onHide: function() {
			console.log('App Hide');
		},
		onError: function(e) {
			console.error('App Error', e.toString());
			this.catchAnomaly(e.toString());
		},
		methods: {
			catchAnomaly(errorMsg) {
				api('error.catchAnomaly', {
					"errorMsg": errorMsg
				}).then(res => {}).catch(() => {});
			},

			// 获取小程序当前版本
			getAppletVersion() {
				try {
					const accountInfo = uni.getAccountInfoSync();
					getApp().version = accountInfo.miniProgram.version;
					console.log("版本号", getApp().version); // 插件版本号， 'a.b.c' 这样的形式
				} catch (e) {
					console.error("获取版本不成功：" + e.toString())
				}
			},

			// 获取小程序版本更新
			upgradeVersion() {

				//获取所有页面栈实例列表
				let pages = getCurrentPages();
				//当前页页面实例
				let nowPage = pages[pages.length - 1];
				if (nowPage.route.endsWith("/purchase-package/purchase-package")) {
					console.warn("purchase-package不更新")
					return;
				}

				const updateManager = uni.getUpdateManager();

				updateManager.onCheckForUpdate(function(res) {
					// 请求完新版本信息的回调
					console.log(res.hasUpdate);
				});

				updateManager.onUpdateReady(function(res) {
					uni.showModal({
						title: '更新提示',
						content: '新版本已经准备好，是否重启小程序？',
						success(res) {
							if (res.confirm) {
								// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
								updateManager.applyUpdate();
							}
						}
					});
				});

				updateManager.onUpdateFailed(function(res) {
					// 新的版本下载失败
				});
			},

			// 消息提示-模态框
			err(message) {
				uni.showModal({
					title: '',
					content: message,
					success(res) {}
				});
			}
		}
	};
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import 'uview-ui/index.scss';

	page {
		background-color: #F7F8F7;
	}

	// 超出长度用...省略。如u-lint-ellipsis-2，满第2行就...省略
	@for $i from 1 through 10 {
		.u-lint-ellipsis-#{$i} {
			text-overflow: -o-ellipsis-lastline;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-line-clamp: $i;
			-webkit-box-orient: vertical;
		}
	}

	.u-flex {
		display: flex;
	}

	.u-flex-row {
		display: flex;
		flex-direction: row;
	}

	.u-flex-column {
		display: flex;
		flex-direction: column;
	}

	.m-flex-column {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		width: 100%;
	}

	.m-flex-row {
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		width: 100%;
	}

	.u-row-between {
		justify-content: space-between !important;
		align-items: center;
	}

	.u-row-around {
		justify-content: space-around !important;
		align-items: center;
	}

	.u-row-start {
		justify-content: start !important;
		align-items: center;
	}

	.u-row-end {
		justify-content: end !important;
		align-items: center;
	}

	.u-row-flex-start {
		justify-content: flex-start !important;
		align-items: center;
	}

	.u-row-flex-end {
		justify-content: flex-end !important;
		align-items: center;
	}

	.u-row-center {
		justify-content: center !important;
		align-items: center !important;
	}

	// 示例：u-font-10标识字号10rpx，范围：1-100
	@for $i from 1 through 100 {
		.u-font-#{$i} {
			font-size: $i + rpx;
		}
	}

	// 示例：u-m-10标识外边距都是10rpx，范围：1-100
	@for $i from 1 through 100 {
		.u-m-#{$i} {
			margin: $i + rpx;
		}
	}

	@for $i from 1 through 100 {
		.u-p-#{$i} {
			padding: $i + rpx;
		}
	}

	@for $i from 1 through 100 {
		.u-m-t-#{$i} {
			margin-top: $i + rpx;
		}
	}

	@for $i from 1 through 100 {
		.u-p-t-#{$i} {
			padding-top: $i + rpx;
		}
	}

	@for $i from 1 through 100 {
		.u-m-r-#{$i} {
			margin-right: $i + rpx;
		}
	}

	@for $i from 1 through 100 {
		.u-p-r-#{$i} {
			padding-right: $i + rpx;
		}
	}

	@for $i from 1 through 100 {
		.u-m-b-#{$i} {
			margin-bottom: $i + rpx;
		}
	}

	@for $i from 1 through 100 {
		.u-p-b-#{$i} {
			padding-bottom: $i + rpx;
		}
	}

	@for $i from 1 through 100 {
		.u-m-l-#{$i} {
			margin-left: $i + rpx;
		}
	}

	@for $i from 1 through 100 {
		.u-p-l-#{$i} {
			padding-left: $i + rpx;
		}
	}
</style>